from django.shortcuts import render
from rest_framework.generics import ListAPIView, RetrieveAPIView
from Healths.models import HealthCategoryModel, HealthDiseaseModel, LifeCategoryModel, LifeDiseaseModel, HealthInfoModel, LifeInfoModel

from Healths.serializers import HealthCategoryModelSerializer, HealthDiseaseModelSerializer, LifeCategoryModelSerializer, \
                                LifeDiseaseModelSerializer, HealthInfoModelSerializer, LifeInfoModelSerializer
from rest_framework.pagination import PageNumberPagination


# 大众健康-健康分类视图
class HealthCategoryListApiView(ListAPIView):
    queryset = HealthCategoryModel.objects.filter(is_show=True, is_deleted=False).order_by('id')
    serializer_class = HealthCategoryModelSerializer


# id
# 大众健康-疾病分类视图
class HealthDiseaseListApiView(ListAPIView):
    serializer_class = HealthDiseaseModelSerializer

    def get_queryset(self):
        healthCategory_id = int(self.kwargs.get('healthCategoryID', 0))
        query_set = HealthDiseaseModel.objects.filter(is_show=True, is_deleted=False).order_by('id')
        if healthCategory_id > 0:
            query_set = query_set.filter(healthCategory=healthCategory_id)
        return query_set


# 生活手册-生活分类视图
class LifeCategoryListApiView(ListAPIView):
    queryset = LifeCategoryModel.objects.filter(is_show=True, is_deleted=False).order_by('id')
    serializer_class = LifeCategoryModelSerializer


# 生活手册-生活技巧视图
class LifeDiseaseListApiView(ListAPIView):
    serializer_class = LifeDiseaseModelSerializer

    def get_queryset(self):
        lifeCategory_id = int(self.kwargs.get('lifeCategoryID', 0))
        query_set = LifeDiseaseModel.objects.filter(is_show=True, is_deleted=False).order_by('id')
        if lifeCategory_id > 0:
            query_set = query_set.filter(lifeCategory=lifeCategory_id)
        return query_set


# 大众健康-健康分类名称视图
class HealthCategoryRetrieveAPIView(RetrieveAPIView):
    queryset = HealthCategoryModel.objects.filter(is_show=True, is_deleted=False)
    serializer_class = HealthCategoryModelSerializer


# 生活手册-生活分类名称视图
class LifeCategoryRetrieveAPIView(RetrieveAPIView):
    queryset = LifeCategoryModel.objects.filter(is_show=True, is_deleted=False)
    serializer_class = LifeCategoryModelSerializer


class Page(PageNumberPagination):
    page_size = 3
    page_query_param = 'page'


# 健康信息视图类
class HealthInfoListAPIView(ListAPIView):
    # queryset = HealthInfoModel.objects.filter(is_pass=True).all()
    serializer_class = HealthInfoModelSerializer
    pagination_class = Page

    def get_queryset(self):
        healthDisease_id = int(self.kwargs.get('healthDiseaseID', 0))
        query_set = HealthInfoModel.objects.filter(is_pass=True).order_by('id')
        if healthDisease_id > 0:
            query_set = query_set.filter(health_disease=healthDisease_id)
        return query_set


# 生活信息视图类
class LifeInfoListAPIView(ListAPIView):
    # queryset = LifeInfoModel.objects.filter(is_pass=True).all()
    serializer_class = LifeInfoModelSerializer
    pagination_class = Page

    def get_queryset(self):
        lifeDisease_id = int(self.kwargs.get('lifeDiseaseID', 0))
        query_set = LifeInfoModel.objects.filter(is_pass=True).order_by('id')
        if lifeDisease_id > 0:
            query_set = query_set.filter(life_disease=lifeDisease_id)
        return query_set


# 健康单条信息详情视图类
class HealthInfoRetrieveAPIView(RetrieveAPIView):
    queryset = HealthInfoModel.objects.filter(is_pass=True).all()
    serializer_class = HealthInfoModelSerializer


# 生活单条信息详情视图类
class LifeInfoRetrieveAPIView(RetrieveAPIView):
    queryset = LifeInfoModel.objects.filter(is_pass=True).all()
    serializer_class = LifeInfoModelSerializer
